Data explanation

This assignment use the Public Assistance Funded Projects Details dataset from FEMA. FEMA provides supplemental Federal disaster grant assistance for debris removal, emergency protective measures, and the repair, replacement, or restoration of disaster-damaged, publicly owned facilities and the facilities of certain Private Non-Profit (PNP) organizations through the PA Program. The data link: https://www.fema.gov/openfema-data-page/public-assistance-funded-projects-details-v1

Data cleaning

#data source: https://www.fema.gov/openfema-data-page/public-assistance-funded-projects-details-v1
public<- read.csv("Public.csv")

#get the year information
public$obligatedYear <-  year(public$obligatedDate)
public$declarationYear <-  year(public$declarationDate)

#when the state code is less than 2 width, fill it up with "0", such as "2" to "02"
#when the county code is less than 2 width, fill it up with "0"
public$states <- formatC(public$stateNumberCode, width = 2, flag = 0)
public$countyc <- formatC(public$countyCode, width = 3, flag = 0)
#combine stateNumberCode and countyCode 
public$fips<- str_c(public$states, public$countyc)
#filter the data into declarationYear between 2009-2018, get only the hurricane data
public.hurricane <- public %>% filter(incidentType ==c("Hurricane","Severe Storm(s)","Coastal Storm"))
public.hurricane%<>% filter(declarationYear>=2009 & declarationYear <=2018)
public.new<-public.hurricane %>% .[-which(.$county == "Statewide"),]

#summarize with each fips, delete the dubricate lines of states and counties
display<- public.new %>% group_by(fips) %>% summarise(n=n(),state=unique(state),county=unique(county),incidentType=unique(incidentType),sumObligated=sum(totalObligated)) %>% rename(GEO_ID = fips)
## `summarise()` regrouping output by 'fips' (override with `.groups` argument)
#round the amount with thousands
display$sumObligated<- display$sumObligated/1000
head(display)
## # A tibble: 6 x 6
## # Groups:   GEO_ID [5]
##   GEO_ID     n state   county  incidentType    sumObligated
##   <chr>  <int> <chr>   <chr>   <chr>                  <dbl>
## 1 01001     13 Alabama Autauga Severe Storm(s)         191.
## 2 01003     77 Alabama Baldwin Severe Storm(s)        4940.
## 3 01003     77 Alabama Baldwin Hurricane              4940.
## 4 01005     24 Alabama Barbour Severe Storm(s)         210.
## 5 01007     10 Alabama Bibb    Severe Storm(s)         444.
## 6 01009     13 Alabama Blount  Severe Storm(s)         415.

-GEO_ID: fips code of the county

-state: state name

-county: county name

-sumObligated: Sum of the federal share of the Public Assistance grant eligible project amount in dollars, plus grantee (State) and sub-grantee (applicant) administrative costs between 2009-2018.

-n:numbers of the funded hurricane projects between 2009-2018

-incidentType: Type of incident:“Hurricane”,“Severe Storm(s)”,“Coastal Storm”


Plot with leaflet

mapping of the funding amount for hurricane disasters

#get the layer of US map from the ".json" file as xy
#The data comes from JSON.
#We’ll use the geojsonio package to load the data from javascrpt into sp objects, which will let us easily manipulate the geographic features, and their properties, in R.
xy <- geojsonio::geojson_read("gz_2010_us_050_00_5m.json", what = "sp")
#names(xy)
#get the string between 10-14 digit of GEO_ID to match the 5-digit string of "fips" 
xy$GEO_ID %<>% substr(start = 10, stop = 14)

# join the US map data with funding data by fips/GEO-ID
leafmap <- geo_join(xy, display, by = "GEO_ID", how = "inner")

#pal function:maps data values "sumObligated" to colors according to a given palette
#pal: colors for the fund amount of hurricanes
pal <- leaflet::colorNumeric(palette = "Blues", domain = leafmap$sumObligated)
#paln: colors for the number of hurricanes
paln<- leaflet::colorNumeric(palette = "Reds", domain = leafmap$n)


#add labels
labels <- sprintf(
  "%s<br/>%s<br/>%s",
  leafmap$state,leafmap$county, leafmap$sumObligated) 
#add popups
popup<- paste0("<strong>state:</strong>", leafmap$state,"<br>",
               "<strong>county:</strong>", leafmap$county,"<br>",
               "<strong>Sum of Obligated Amount:</strong>",round(leafmap$sumObligated,2),"thousand")
popupn<- paste0("<strong>state:</strong>", leafmap$state,"<br>",
                "<strong>county:</strong>", leafmap$county,"<br>",
                "<strong>Number of funded hurricane projects:</strong>",leafmap$n)

#mapping by leaflet,showing the sum between 2009-2018
leaflet() %>%
  #titles
  addTiles() %>%
  addProviderTiles("CartoDB.Positron") %>%
  addProviderTiles(providers$Stamen.TonerLines,
                   options = providerTileOptions(opacity = 0.75)) %>%
  
  setView(-89.275673, 37.098, zoom = 4) %>%
  addPolygons(data = leafmap, 
              fillColor = ~pal(sumObligated), 
              color = "#BDBDC3",
              fillOpacity = 1, 
              weight = 1, 
              smoothFactor = 0.2,
              
              popup= popup,
              popupOptions = popupOptions(
                style = list("font-weight" = "normal", padding = "3px 8px"),
                textsize = "15px",
                direction = "auto")
              
              ) %>%
  addLegend(pal = pal, 
            values = leafmap$sumObligated, 
            position = "bottomright", 
            title = paste0("Sum obligated amount(in thousands)<br>2009-2018")) 

mapping for the numbers of hurricanes funded projects

leaflet() %>%
  #titles
  addTiles() %>%
  addProviderTiles("CartoDB.Positron") %>%
  addProviderTiles(providers$Stamen.TonerLines,
                   options = providerTileOptions(opacity = 0.75)) %>%
  
  setView(-89.275673, 37.098, zoom = 4) %>%
  addPolygons(data = leafmap, 
              fillColor = ~paln(n), 
              color = "#BDBDC3",
              fillOpacity = 1, 
              weight = 1, 
              smoothFactor = 0.2,
              
              popup= popupn,
              popupOptions = popupOptions(
                style = list("font-weight" = "normal", padding = "3px 8px"),
                textsize = "15px",
                direction = "auto")
              
  ) %>%
  addLegend(pal = paln, 
            values = leafmap$n, 
            position = "bottomright", 
            title = paste0("Numbers of funded hurricane projects<br>2009-2018"))